var express = require('express');
var http = require('http');
var bodyParser = require('body-parser');

var app = express();

var port = 3030;

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.get('/recv', (req, res) => {
  console.log('get param message : ' + req.query.message)
  res.json({
    header: {
      code: 'success'
    },
    method: 'get',
    timestamp: new Date().getTime()
  });
});

app.post('/recv', (req, res) => {
  console.log('post body message : ' + req.body.message)
  res.json({
    header: {
      code: 'success'
    },
    method: 'post',
    timestamp: new Date().getTime()
  });
});

app.post('/recv/json', (req, res) => {
  console.log('json body message : ' , req.body)
  res.json({
    header: {
      code: 'success'
    },
    method: 'json',
    timestamp: new Date().getTime()
  });
});


var server = http.createServer(app);

server.listen(port);

server.on('listening', () => {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  console.log('Listening on ' + bind);
});
